/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package BL;

import java.io.Serializable;
import java.util.Collection;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;

/**
 *
 * @author sundas
 */
@Entity
@Table(name = "customer", catalog = "newPurchase", schema = "", uniqueConstraints = {@UniqueConstraint(columnNames = {"customerId"})})
@NamedQueries({@NamedQuery(name = "Customer.findAll", query = "SELECT c FROM Customer c"), @NamedQuery(name = "Customer.findByCompanyName", query = "SELECT c FROM Customer c WHERE c.companyName = :companyName"), @NamedQuery(name = "Customer.findByCompanyContact", query = "SELECT c FROM Customer c WHERE c.companyContact = :companyContact"), @NamedQuery(name = "Customer.findByCustomerId", query = "SELECT c FROM Customer c WHERE c.customerId = :customerId")})
public class Customer implements Serializable {
    private static final long serialVersionUID = 1L;
    @Column(name = "companyName", length = 50)
    private String companyName;
    @Column(name = "companyContact", length = 50)
    private String companyContact;
    @Id
    @Basic(optional = false)
    @Column(name = "customerId", nullable = false)
    private Integer customerId;
    @JoinColumn(name = "NIC", referencedColumnName = "NIC")
    @ManyToOne
    private Person nic;
    @OneToMany(mappedBy = "customerId")
    private Collection<Prodorder> prodorderCollection;

    public Customer() {
    }

    public Customer(Integer customerId) {
        this.customerId = customerId;
    }

    public String getCompanyName() {
        return companyName;
    }

    public void setCompanyName(String companyName) {
        this.companyName = companyName;
    }

    public String getCompanyContact() {
        return companyContact;
    }

    public void setCompanyContact(String companyContact) {
        this.companyContact = companyContact;
    }

    public Integer getCustomerId() {
        return customerId;
    }

    public void setCustomerId(Integer customerId) {
        this.customerId = customerId;
    }

    public Person getNic() {
        return nic;
    }

    public void setNic(Person nic) {
        this.nic = nic;
    }

    public Collection<Prodorder> getProdorderCollection() {
        return prodorderCollection;
    }

    public void setProdorderCollection(Collection<Prodorder> prodorderCollection) {
        this.prodorderCollection = prodorderCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (customerId != null ? customerId.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Customer)) {
            return false;
        }
        Customer other = (Customer) object;
        if ((this.customerId == null && other.customerId != null) || (this.customerId != null && !this.customerId.equals(other.customerId))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "DB.Customer[customerId=" + customerId + "]";
    }

}
